home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 1 / Atari Mega Archive - Volume 1.iso / telecomm / sticpsrc.lzh / SOURCE.ARC / MAIN.C < prev    next >
Text File  |  1990-10-06  |  43KB  |  1,849 lines

  1. /* Main network program - provides both client and server functions */
  2.  
  3. #define HOSTNAMELEN 32        /* changed from 16 by Bdale 860812 */
  4.  
  5. extern char STARTUP[];        /* File to read startup commands from */
  6. extern char ONEXIT[];        /* File to read termination commands from */
  7.  
  8. #include <stdio.h>
  9.  
  10. #ifdef ATARI_ST
  11. # ifdef MWC
  12. #  include <osbind.h>
  13. #  include <basepage.h>
  14. # endif
  15. # ifdef __TURBOC__
  16. #  include <tos.h>
  17. extern char *_BasPag;        /* base page pointer */
  18. #  define BP    *_BasPag
  19. # endif
  20. #endif
  21.  
  22. #include "global.h"
  23. #include "config.h"
  24. #include "mbuf.h"
  25. #include "buffers.h"
  26. #include "netuser.h"
  27. #include "timer.h"
  28. #include "icmp.h"
  29. #include "iface.h"
  30. #include "ip.h"
  31. #include "tcp.h"
  32. #include "ax25.h"
  33. #include "lapb.h"
  34. #include "ftp.h"
  35. #include "telnet.h"
  36. #include "remote.h"
  37. #ifdef    SCREEN
  38. #include "screen.h"
  39. #endif
  40. #include "session.h"
  41. #include "cmdparse.h"
  42. #include "kiss.h"
  43. #include "slip.h"
  44. #include "tnc2.h"
  45.  
  46. #ifdef    ASY
  47. #include "asy.h"
  48. #endif
  49.  
  50. #ifdef    NRS
  51. #include "nrs.h"
  52. #endif
  53.  
  54. #ifdef    UNIX        /* BSD or SYS5 */
  55. #include <termio.h>
  56. #include "unix.h"
  57. #endif
  58.  
  59. #ifdef    AMIGA
  60. #include "amiga.h"
  61. #endif
  62.  
  63. #ifdef    MAC
  64. #include "mac.h"
  65. #endif
  66.  
  67. #ifdef    CPM
  68. #include "cpm.h"
  69. #endif
  70.  
  71. #ifdef    TRACE
  72. #include "trace.h"
  73. /* Dummy structure for loopback tracing */
  74. struct interface loopback = { NULLIF, "loopback" };
  75. #endif
  76.  
  77. extern char version[];
  78. extern int vercheck;
  79. extern struct mbuf *loopq;
  80. extern struct mbuf *axloopq;
  81. extern FILE *trfp;
  82. extern char trname[];
  83.  
  84. int flowctrl = 0;
  85. int mode;
  86. FILE *logfp;
  87. char logname[40];
  88. long starttime;
  89. char badhost[] = "Unknown host \"%s\"\n";
  90. char cantopen[] = "%s: cannot open\n";
  91. char hostname[HOSTNAMELEN];
  92. unsigned nsessions = NSESSIONS;
  93. int32 resolve();
  94. int16 lport = 1001;
  95. char prompt[] = "net> ";
  96. char nospace[] = "No space!!\n";    /* Generic malloc fail message */
  97.  
  98. static void log_finish();
  99.  
  100. #if    (!defined(MSDOS) && !defined(ATARI_ST)) /* PC/Atari uses F-10 key */
  101. static int escape = 0x1d;        /* default escape character is ^] */
  102. #else
  103. static int escape = -2;            /* this corrensponds to F10 key */
  104. #endif
  105.  
  106. /* Command lookup and branch table */
  107. int go(),doax25(),cmdmode(),doconnect(),dotelnet(),doexit(),doclose(),
  108.     dohostname(),doreset(),dotcp(),dotrace(),doescape(),dohelp(),dohost(),
  109.     doroute(),doecho(),doflow(),dolog(),doip(),doetherstat(),
  110.     memstat(),doarp(),dosession(),doftp(),dostart(),dostop(),doattach(),
  111.     dosmtp(),doudp(),doparam(),doeol(),dohapnstat(),dobuffers(),
  112.     doegstat(),dodump(),dorecord(),doupload(),dokick(),domode(),doshell(),
  113.     dodate(),dodelete(),dodir(),docd(),docopy(),dorename(),dormdir(),domkdir(),
  114.     dotype(),doatstat(),doping(),dosource(),domheard(),dofinger(),
  115.     domorom(),donrstat(),dosccstat(),doauxcon(),doforward(),doremote(),
  116.     doscreen(),dosetenv(),dowatchdog(),doat(),dolatency();
  117.  
  118. struct cmds cmds[] = {
  119.     /* The "go" command must be first */
  120.     "",        go,        0, NULLCHAR,    NULLCHAR,
  121. #ifndef CPM
  122.     "!",        doshell,    0, NULLCHAR,    "cannot run shell",
  123. #endif
  124. #if    (defined(MAC) && defined(APPLETALK))
  125.     "applestat",    doatstat,    0, NULLCHAR,    NULLCHAR,
  126. #endif
  127. #if    (defined(IP) && (defined(AX25) || defined(ETHER) || defined(APPLETALK)))
  128.     "arp",        doarp,        0, NULLCHAR,    NULLCHAR,
  129. #endif
  130. #if (!defined(MSDOS) || defined(MSC) || defined(__TURBOC__))
  131.     "at",        doat,        0, NULLCHAR,    NULLCHAR,
  132. #endif
  133.     "attach",    doattach,    2,
  134.         "<hardware> <hw specific options>", NULLCHAR,
  135. #if    (defined(ATARI_ST) && defined(MWC))
  136.     "auxcon",    doauxcon,    2, "<io code> [speed [7|8 [noflow]]]", NULLCHAR,
  137. #endif
  138. #ifdef    AX25
  139.     "ax25",        doax25,        0, NULLCHAR,    NULLCHAR,
  140. #endif
  141. #ifdef    SCC
  142.     "buffers",    dobuffers,    0, NULLCHAR,    NULLCHAR,
  143. #endif
  144. /* This one is out of alpabetical order to allow abbreviation to "c" */
  145. #ifdef    AX25
  146.     "connect",    doconnect,    3, "<interface> <callsign> [digipeaters]",
  147.         NULLCHAR,
  148. #endif
  149. #if    (!defined(CPM) && !defined(UNIX))   /* BSD or SYS5 */
  150.     "cd",        docd,        0, NULLCHAR,    NULLCHAR,
  151. #endif
  152.     "close",    doclose,    0, NULLCHAR,    NULLCHAR,
  153. #if    (!defined(CPM) && !defined(UNIX))   /* BSD or SYS5 */
  154.     "copy",        docopy,        3, "<file> ... <dest>", NULLCHAR,
  155.     "date",        dodate,        0, NULLCHAR,    "Usage: date [mmddhhmmss[yy]]",
  156.     "delete",    dodelete,    2, "[-f] <file> ...", NULLCHAR,
  157.     "dir",        dodir,        0, NULLCHAR,    NULLCHAR,
  158. #endif
  159.     "disconnect",    doclose,    0, NULLCHAR,    NULLCHAR,
  160. #ifdef    EAGLE
  161.     "eaglestat",    doegstat,    0, NULLCHAR,    NULLCHAR,
  162. #endif
  163. #ifdef    IP
  164.     "echo",        doecho,        0, NULLCHAR,    "echo options: refuse accept",
  165.     "eol",        doeol,        0, NULLCHAR,    "eol options: unix standard",
  166. #endif
  167.     "escape",    doescape,    0, NULLCHAR,    NULLCHAR,
  168. #ifdef    PC_EC
  169.     "etherstat",    doetherstat,    0, NULLCHAR,    NULLCHAR,
  170. #endif
  171.     "exit",        doexit,        0, NULLCHAR,    NULLCHAR,
  172. #ifdef    IP
  173.     "finger",    dofinger,    2, "[<user>][@<host>]",
  174.                     "Usage: finger <user> | <user>@<host> | @<host>",
  175. #endif
  176.     "flow",        doflow,        0, NULLCHAR,    NULLCHAR,
  177.     "forward",    doforward,    0, NULLCHAR,    NULLCHAR,
  178. #if    (defined(IP) && defined(FTPC))
  179.     "ftp",        doftp,        2, "<address> [<port> [<tos>]]",        NULLCHAR,
  180. #endif
  181. #ifdef    HAPN
  182.     "hapnstat",    dohapnstat,    0, NULLCHAR,    NULLCHAR,
  183. #endif
  184.     "help",        dohelp,        0, NULLCHAR,    NULLCHAR,
  185. #ifdef    IP
  186.     "host",        dohost,        2, "<hostname>|[ip_address]",    NULLCHAR,
  187.     "hostname",    dohostname,    0, NULLCHAR,    NULLCHAR,
  188.     "ip",        doip,        0, NULLCHAR,    NULLCHAR,
  189. #endif
  190.     "kick",        dokick,        0, NULLCHAR,    NULLCHAR,
  191. #ifdef    ATARI_ST
  192.     "latency",    dolatency,    2, "yes|no|raw|stat", "Usage: latency yes|no|raw|stat",
  193. #endif
  194. #ifdef    SERVERS
  195.     "log",        dolog,        0, NULLCHAR,    NULLCHAR,
  196. #endif
  197. #if    (defined(MSDOS) || defined(ATARI_ST) || defined(UNIX))
  198.     "memstat",    memstat,    0, NULLCHAR,    NULLCHAR,
  199. #endif
  200. #ifdef    MHEARD
  201.     "mheard",    domheard,    2, "<interface> [<maxheard>|clear]", NULLCHAR,
  202. #endif
  203. #if    (!defined(CPM) && !defined(UNIX))   /* BSD or SYS5 */
  204.     "mkdir",    domkdir,    2, "[-f] <dir> ...", NULLCHAR,
  205. #endif
  206. #if (defined(IP) && defined(AX25))
  207.     "mode",        domode,        2, "<interface>",  NULLCHAR,
  208. #endif
  209. #ifdef    NETROM
  210.     "morom",    domorom,    0, NULLCHAR,    NULLCHAR,
  211. #endif
  212. #ifdef    NRS
  213.     "nrstat",    donrstat,    0, NULLCHAR,    NULLCHAR,
  214. #endif
  215.     "param",    doparam,    2, "<interface>", NULLCHAR,
  216. #ifdef    IP
  217.     "ping",        doping,        0, NULLCHAR,    NULLCHAR,
  218. #endif
  219. #if    (!defined(CPM) && !defined(UNIX))   /* BSD or SYS5 */
  220.     "pwd",        docd,        0, NULLCHAR,    NULLCHAR,
  221. #endif
  222.     "record",    dorecord,    0, NULLCHAR,    NULLCHAR,
  223. #ifdef    IP
  224.     "remote",    doremote,    4, "<address> <port> <command>",
  225.                             NULLCHAR,
  226. #endif
  227. #if    (!defined(CPM) && !defined(UNIX))   /* BSD or SYS5 */
  228.     "rename",    dorename,    3, "<oldname> <newname>", NULLCHAR,
  229. #endif
  230.     "reset",    doreset,    0, NULLCHAR,    NULLCHAR,
  231. #if    (!defined(CPM) && !defined(UNIX))   /* BSD or SYS5 */
  232.     "rmdir",    dormdir,    2, "[-f] <dir> ...", NULLCHAR,
  233. #endif
  234. #ifdef    IP
  235.     "route",    doroute,    0, NULLCHAR,    NULLCHAR,
  236. #endif
  237. /* This one is out of alpabetical order to allow abbreviation to "s" */
  238.     "session",    dosession,    0, NULLCHAR,    NULLCHAR,
  239. #ifdef    SCC
  240.     "sccstat",    dosccstat,    0, NULLCHAR,    NULLCHAR,
  241. #endif
  242. #if    (defined(ATARI_ST) && defined(MWC))
  243.     "screen",    doscreen,    2, "bios|direct|tos", "screen options: bios direct tos",
  244. #endif
  245.     "setenv",    dosetenv,    0, NULLCHAR,    "setenv failed",
  246. #ifndef CPM
  247.     "shell",    doshell,    0, NULLCHAR,    "cannot run shell",
  248. #endif
  249. #if    (defined(IP) && defined(SMTPC))
  250.     "smtp",        dosmtp,        0, NULLCHAR,    NULLCHAR,
  251. #endif
  252.     "source",    dosource,    2, "<file>", NULLCHAR,
  253. #ifdef    SERVERS
  254.     "start",    dostart,    2, "<servername>",NULLCHAR,
  255.     "stop",        dostop,        2, "<servername>", NULLCHAR,
  256. #endif
  257. #ifdef    IP
  258.     "tcp",        dotcp,        0, NULLCHAR,    NULLCHAR,
  259.     "telnet",    dotelnet,    2, "<address> [<port> [<tos>]]",     NULLCHAR,
  260. #endif
  261. #ifdef    TRACE
  262.     "trace",    dotrace,    0, NULLCHAR,    NULLCHAR,
  263. #endif
  264. #if    (!defined(CPM) && !defined(UNIX))   /* BSD or SYS5 */
  265.     "type",        dotype,        2, "<file> [<lines>]", NULLCHAR,
  266. #endif
  267. #ifdef    IP
  268.     "udp",        doudp,        0, NULLCHAR,    NULLCHAR,
  269. #endif
  270.     "upload",    doupload,    0, NULLCHAR,    NULLCHAR,
  271. #if    (defined(MSDOS) || defined(ATARI_ST))
  272.     "watchdog",    dowatchdog,    0, NULLCHAR,    NULLCHAR,
  273. #endif
  274.     "?",        dohelp,        0, NULLCHAR,    NULLCHAR,
  275.     NULLCHAR,    NULLFP,        0,
  276.         "Unknown command; type \"?\" for list", NULLCHAR
  277. };
  278.  
  279. #ifdef    SERVERS
  280. /* "start" and "stop" subcommands */
  281. int dis1(),echo1(),fin